<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class model_reporting extends CI_Model{
    var $table      = "tbl_kasus";
    var $table_jk   = "tbl_jenis_kasus";
    var $table_sak  = "tbl_saksi";
    var $tbl_city   = "master_city";
    var $tbl_state  = "master_state";
    var $tbl_member = "tbl_member";
    var $primary    = "id_kasus";
    public function __construct()
    {
        parent::__construct();
    }
    
    function get_paged_list($limit = 20, $offset = 0, $order_column='datecreated', $order_type='DSC'){
        if(empty($order_column)||empty($order_type)){
            $this->db->order_by("datecreated",'DESC');	
    	}else{
            $this->db->order_by($order_column,$order_type);
            return $this->db->get($this->table, $limit, $offset);
    	}
    }
    
    function get_all(){
        $q = $this->db->query("SELECT A.*,B.name,B.email as email_pelapor FROM `".$this->table."` as A "
                . "LEFT OUTER JOIN `".$this->tbl_member."` as B ON A.`createdby` = B.`id_member` ORDER BY A.datecreated DESC");
        return $q->result();
    }
    function select_by_id($id){
        $query = "SELECT A.*,B.name,B.email,C.state_name,D.city_name,E.state_name as dk_propinsi_name,F.city_name as dk_city_name FROM `".$this->table."` as A "
                . "LEFT OUTER JOIN `".$this->tbl_member."` as B ON A.`createdby` = B.`id_member` "
                . "INNER JOIN `".$this->tbl_state."` as C ON A.`korban_propinsi` = C.`state_id` "
                . "INNER JOIN `".$this->tbl_city."` as D ON D.`city_id` = A.`korban_kota`"
                . "INNER JOIN `".$this->tbl_state."` as E ON A.`dk_propinsi` = E.`state_id`"
                . "INNER JOIN `".$this->tbl_city."` as F ON A.`dk_kota` = F.`city_id` "
                . "WHERE `".$this->primary."` = '".$id."'";
        $q = $this->db->query($query);
        return $q->result();
    }
    function count_by_id($id){
        $q= $this->db->query("SELECT * FROM `".$this->table."` WHERE `".$this->primary."` = '".$id."'");
        return $q->num_rows();
    }
    function map_grouping_provinsi() {
        $q = $this->db->query(
            "SELECT 
                P.`id_provinsi`,
                P.`lat`,
                P.`long`,
                P.nama_provinsi,COUNT(*) as jumlah 
            FROM `tbl_kasus` as K LEFT 
            JOIN `tbl_provinsi` as P ON K.`id_provinsi` = P.`id_provinsi` 
            GROUP BY K.`id_provinsi`");
        return $q->result();
    }
    
    function save_tata($isi){
        $this->db->insert("tatacara",$isi);
    }
    function delete($id){
        return true;
//        if( empty($id) ) return false;
//        if($this->db->delete($this->table, array($this->primary => $id))) return true;
//        else return false; 
    }
    function update($id,$array){
        $this->db->where($this->primary,$id);	
        if(!$this->db->update($this->table,$array))return FALSE;
        else return TRUE;
    }
    
}
/* End of file model_reporting.php */
/* Location: ./application/models/model_reporting.php */
